package com.example.front.controller;

import com.example.front.service.ProductService;
import com.example.front.vo.ProductDetailVo;
import com.github.pagehelper.PageInfo;
import com.example.gok_mall.reponseData.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/productFront")
@ResponseBody
public class ProductController {

    @Autowired
    private ProductService productService;

    //前台查询商品详情接口
    @GetMapping("detail.do")
    public ResultData<ProductDetailVo> detail(Integer productId){
        return productService.getProductDetail(productId);
    }


    //前台查询商品列表接口
    @GetMapping("list.do")
    //商品详情列表分页
    public ResultData<PageInfo> list(@RequestParam(value = "keyword",required = false) String keyword,
            @RequestParam(value = "categoryId",required = false)Integer categoryId,
            @RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,
            @RequestParam(value = "orderBy",defaultValue = "") String orderBy){

        return productService.getProductByKeywordCategory(keyword,categoryId,pageNum,pageSize,orderBy);
    }

}
